$(function(){
	var url = $.query.get("url");
	$(".title span:first").append(loading);
	$( "#radio1,#radio2,#radio3,#radio4" ).buttonset();
	$("body").css("width",$(window).width()-20);
	$(".reader").attr("style","width:75%; matin:10px auto;");
	
	//init kzContent style
	var configStr = localStorage.configs || JSON.stringify({"color":"#000","fontSize":"16px","backgroundColor":"#ffffff","width":"0.75"});
	var configs = JSON.parse(configStr);
	localStorage.setItem("configs",configStr);
	$("#kzContent").css("font-size",configs.fontSize);
	$("#kzContent").css("color","#"+configs.fontColor);
	$("#kzContent").css("background","#"+configs.backgroundColor);
	$("#kzContent").css("width",configs.width*$(window).width()-20);
	
	//init toolbar
	var radio1 = $("input[name='radio1'][value='"+configs.fontSize+"']");
	radio1.attr("checked",true);
	$("label[for='"+radio1.attr("id")+"']").addClass("ui-state-active");
	$("label[for='"+radio1.attr("id")+"']").attr("aria-pressed","true");
	$("#fontColor").val(configs.fontColor);
	var radio2 = $("input[name='radio2'][value='"+configs.backgroundColor+"']");
	radio2.attr("checked",true);
	$("label[for='"+radio2.attr("id")+"']").addClass("ui-state-active");
	$("label[for='"+radio2.attr("id")+"']").attr("aria-pressed","true");
	$("#contentWidth").val(configs.width);
	
	//toolbar bind event
	$("#radio1 label").click(function(){
		$("input[name='radio1'][checked]").attr("checked",false);
		$("#"+$(this).attr('for')).attr("checked",true);
		$("#kzContent").css("font-size",$("input[name='radio1'][checked]").val());
		var json = JSON.parse(localStorage.configs);
		json.fontSize = $("input[name='radio1'][checked]").val();
		localStorage.setItem("configs",JSON.stringify(json));
	});
	$("#radio2 label").click(function(){
		$("input[name='radio2'][checked]").attr("checked",false);
		$("#"+$(this).attr('for')).attr("checked",true);
		$("#kzContent").css("background","#"+$("input[name='radio2'][checked]").val());
		var json = JSON.parse(localStorage.configs);
		json.backgroundColor = $("input[name='radio2'][checked]").val();
		localStorage.setItem("configs",JSON.stringify(json));
	});
	$("#contentWidth").change(function(){
		$("#kzContent").css("width",$(this).val()*$(window).width()-20);
		var json = JSON.parse(localStorage.configs);
		json.width = $(this).val();
		localStorage.setItem("configs",JSON.stringify(json));
	});
	$("#fontColor").change(function(){
		$("#kzContent").css("color","#"+$(this).val());
		var json = JSON.parse(localStorage.configs);
		json.fontColor = $(this).val();
		localStorage.setItem("configs",JSON.stringify(json));
	});
	
	$.get(uri+url,function(html){
		$(".title").find(loading).remove();
		$(".title span:first").append($(html).find(".bi").text());
		$("#kzContent").html($(html).find("#kz_content").html());
	});
})